/*
 *    DynamicInstanceStream.java
 *    @author Manuel Baena (mbaena@uma.es)
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package moa.streams;

import java.util.ArrayList;
import java.util.Enumeration;

import weka.core.Attribute;
import weka.core.Instance;
import weka.core.Instances;

/**
 * Interface representing a data stream of dynamic instances. 
 *
 * @author Manuel Baena (mbaena@uma.es)
 * @version $Revision: 1 $ 
 */
public interface DynamicInstanceStream extends InstanceStream {
	
	public static enum StructuralChangeType{
		ADD_ATTRIBUTE, DELETE_ATTRIBUTE, ADD_ATTRIBUTE_VALUE, DELETE_ATTRIBUTE_VALUE, ADD_LABEL, DEL_LABEL
	}
	
    public static class StructuralChangeInstance implements Instance {
    	public StructuralChangeType type;
    	public Attribute attribute;
    	public String value;

    	public StructuralChangeInstance(StructuralChangeType type, Attribute attribute) {
    		this.type = type;
    		this.attribute = attribute;
		}
    	
    	public StructuralChangeInstance(StructuralChangeType type, Attribute attribute, String val) {
    		this.type = type;
    		this.attribute = attribute;
    		this.value = val;
		}

		@Override
		public Object copy() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Attribute attribute(int index) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Attribute attributeSparse(int indexOfIndex) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Attribute classAttribute() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public int classIndex() {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public boolean classIsMissing() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public double classValue() {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public Instances dataset() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void deleteAttributeAt(int position) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public Enumeration enumerateAttributes() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public boolean equalHeaders(Instance inst) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public String equalHeadersMsg(Instance inst) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public boolean hasMissingValue() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public int index(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public void insertAttributeAt(int position) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public boolean isMissing(int attIndex) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean isMissingSparse(int indexOfIndex) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean isMissing(Attribute att) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public Instance mergeInstance(Instance inst) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public int numAttributes() {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public int numClasses() {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public int numValues() {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public void replaceMissingValues(double[] array) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setClassMissing() {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setClassValue(double value) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setClassValue(String value) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setDataset(Instances instances) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setMissing(int attIndex) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setMissing(Attribute att) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setValue(int attIndex, double value) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setValueSparse(int indexOfIndex, double value) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setValue(int attIndex, String value) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setValue(Attribute att, double value) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setValue(Attribute att, String value) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void setWeight(double weight) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public Instances relationalValue(int attIndex) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Instances relationalValue(Attribute att) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public String stringValue(int attIndex) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public String stringValue(Attribute att) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public double[] toDoubleArray() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public String toStringNoWeight() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public String toString(int attIndex) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public String toString(Attribute att) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public double value(int attIndex) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public double valueSparse(int indexOfIndex) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public double value(Attribute att) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public double weight() {
			// TODO Auto-generated method stub
			return 0;
		}    	
	}
    
    public static class StructuralChangeHelper {
    	
    	public static Instances addAttribute(Instances insts, Attribute att) {
    		insts.insertAttributeAt(att, att.index());
    		return insts;
    	}
    	
    	public static Instances delAttribute(Instances insts, String attributeName) {
			ArrayList<Attribute> attributes = new ArrayList<Attribute>();
			for (int i=0; i<insts.numAttributes(); i++) {
    			if (insts.attribute(i).name().equals(attributeName)) {
    				continue;
    			}
    			attributes.add(insts.attribute(i));
    		}
    		return new Instances(insts.relationName(), attributes, 0);
    	}
    	
    	public static Instances addAttributeValue(Instances insts, String attributeName, String val) {
			Attribute attribute = insts.attribute(attributeName);
			ArrayList<String> attributeValues = new ArrayList<String>();
			for (int i=0; i < attribute.numValues(); i++) {
				attributeValues.add(attribute.value(i));
			}
			attributeValues.add(val);
		    attribute = new Attribute(attributeName,
					attributeValues, attribute.index());
    		insts = delAttribute(insts, attributeName);
    		insts.insertAttributeAt(attribute, attribute.index());
    		return insts;
    	}
    	
    	public static Instances delAttributeValue(Instances insts, String attributeName, String val) {
			Attribute attribute = insts.attribute(attributeName);
			ArrayList<String> attributeValues = new ArrayList<String>();
			for (int i=0; i < attribute.numValues(); i++) {
				if (val.equals(attribute.value(i))) {
					continue;
				}
				attributeValues.add(attribute.value(i));
			}
		    attribute = new Attribute(attributeName,
					attributeValues, attribute.index());
		    insts = delAttribute(insts, attributeName);
		    insts.insertAttributeAt(attribute, attribute.index());
		    return insts;
    	}
    }

}
